package grafico;

import grafico.imagen.AdministradorGrafico;

import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


import javax.swing.JPanel;

import Logica.Interfaz;

public class Tablero extends JPanel{
	protected boolean blanco=true;
	public Tablero()
	{
		addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent evt) {
				Interfaz I=Interfaz.getInstance();
				int x,y;char c;
				x=evt.getX()/(551/19)+1;
				y=evt.getY()/(551/19)+1;
				if(blanco) c='b'; else c='n';
				boolean inserto= I.insertar(x,y,c);
				repaint();
				if(inserto)blanco=!blanco;
				else if(!I.hayFicha(x, y, 'b')&&!I.hayFicha(x, y, 'n'))
				{System.out.println("suicidio");
					Ventana.getInstance().mostrarCartelSuicidio();}
				Ventana.getInstance().cambiarturnos(blanco);
				
			}
		});
	}
	
	
	
  // @Override
   public void paint(Graphics g) {

	   Interfaz I=Interfaz.getInstance();
        for(int y=0;y<19;y++)
        	for(int x=0;x<19;x++)
        	  	if(I.hayFicha(x+1, y+1,'b'))	
        	  		g.drawImage(AdministradorGrafico.getInstance().getImagen("FichaBlanca"), 
        	  				((this.getHeight())/19)*x,((this.getHeight())/19)*y,
        	  				this.getHeight()/19,	this.getHeight()/19, null);
        		
        	  	else if(I.hayFicha(x+1, y+1,'n'))	
        	  		g.drawImage(AdministradorGrafico.getInstance().getImagen("FichaNegra"), 
        	  				((this.getHeight())/19)*x,((this.getHeight())/19)*y,
        	  				this.getHeight()/19,	this.getHeight()/19, null);
        	
            }



public void setTurnoBlanco(boolean b) {
	blanco=b;
	Ventana.getInstance().cambiarturnos(blanco);
}
   
   
	
}
	

